package com.alien.smartmusicplayer.textproject;

import android.app.KeyguardManager;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.text.method.MetaKeyKeyListener;
import android.util.Log;

/**
 * Created by Alien_yuan on 2015/11/23.
 */
public class LockScreenService extends Service {
    private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d("alien","LockScreenService:onReceive-" + intent.getAction());
            Intent lockScreen = new Intent();
            lockScreen.setClass(context,LockScreenView.class);
            lockScreen.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            lockScreen.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
            context.startActivity(lockScreen);
        }
    };
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        Log.d("alien","LockScreenService:onBind-" + intent.getAction());
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public void onStart(Intent intent, int startId) {
        super.onStart(intent, startId);
        IntentFilter intentFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
        intentFilter.setPriority(1000);
        this.registerReceiver(broadcastReceiver, intentFilter);
    }

    @Override
    public void onDestroy() {
        this.unregisterReceiver(broadcastReceiver);
        super.onDestroy();
    }
}
